/*
 * Copyright (c) 2015 Messcat. All rights reserved.
 */
package com.rc.saas.tenant.common.utils;


import com.rc.saas.tenant.common.constant.CommonConstant;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Microcat
 * @version 1.0
 */
public class StringUtil {

	public static boolean isBlank(String str) {
		if (str == null || str.length() == 0) {
			return true;
		}
		return false;
	}

	public static boolean isNotBlank(String str) {
		return !isBlank(str);
	}

	public static String getGetterMethodName(String fieldName) {
		String getter = CommonConstant.CONSTANT_STRING_GET + toUpperCaseFirstLetter(fieldName);
		return getter;
	}

	public static String getSetterMethodName(String fieldName) {
		String setter = CommonConstant.CONSTANT_STRING_SET + toUpperCaseFirstLetter(fieldName);
		return setter;
	}

	public static String toUpperCaseFirstLetter(String str) {
		return str.substring(0, 1).toUpperCase() + str.substring(1);
	}

	public static String toLowerCaseFirstLetter(String str) {
		return str.substring(0, 1).toLowerCase() + str.substring(1);
	}

    /**
     * 自增编号
     * @param lastNo 需要自增的编码
     * @param num 计算last数字自增+1
     * @return
     */
    public static String newNo(String lastNo,int num){
        String newNo = "";
        String startNo = lastNo.substring(0,lastNo.length()-num);
        String endNo =  lastNo.substring(lastNo.length()-num);
        int numNo = Integer.valueOf("1"+endNo)+1;
        newNo = startNo+(String.valueOf(numNo).substring(1,String.valueOf(numNo).length()));
        return newNo;
    }


    /**
     * 返回桩编号
     * @param lastNo
     * @return
     */
    public static String newPileNo(String lastNo){
        String stationNo = lastNo.substring(0, 8);//

        String pileNo = lastNo.substring(lastNo.length() - 4, lastNo.length() - 1);
        String newPileNo = String.format("%03d", Integer.valueOf(pileNo) + 1);
        if (newPileNo.length() == 4) {
            throw new RuntimeException("桩编号超出999,对应桩编号:" + lastNo);
        }

        return stationNo + newPileNo + "1";
    }

    public static String stringArray2Strin(String[] str) {

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length; i++) {
            sb.append("'").append(str[i]).append("'").append(",");
        }
        return sb.toString().substring(0, sb.length() - 1);
    }

    public static void main(String[] args) {
        String str = ",6,8";
        System.out.println(stringArray2Strin(str.split(",")));
    }
}
